package cn.pegasus.teamwork.util;


import java.util.HashMap;
import java.util.Map;

import net.sf.json.JSONObject;

/**
 * 错误代码枚举类，用来标识错误描述
 * 
 * @author wangzhenjiang
 *
 */
public enum ErrorCode {



	/** 成功 {errorCode:0} */
	error_0(200, "成功"),
	error_1001(1001,"操作失败"),
	error_1002(1002,"数据库读写错误"),
	error_1003(1003,"参数有误"),
	error_1004(1004,"查找对象不存在"),
	error_1005(1005,"系统繁忙"),
	error_1006(1006,"上传超时"),
	error_1007(1007,"图片验证码错误"),
	error_1008(1008,"非法请求"),
	error_1009(1009,"返回信息对象错误"),
	error_1010(1010,"上传失败"),
	error_1011(1011,"未登录或登录信息失效"),
	error_1012(1012,"csrf token认证错误"),
	error_1013(1013,"加密消息服务器连接失败"),
	error_1014(1014,"加密消息服务器加密通知失败"),
	error_1015(1015,"access token认证失败"),
	error_1016(1016,"access token已过期"),
	error_1017(1017,"文件分享失败"),
	error_1018(1018,"文件轨迹不存在"),
	error_1019(1019,"Redis服务器错误"),
	error_1020(1020,"分享时间不能早于当前时间"),
	error_1044(1044,"未知错误"),
	error_1050(1050,"邀请码有效"),
	error_1051(1051,"邀请码无效"),
	error_1052(1052,"邀请码已使用"),
	error_1053(1053,"邀请码信息错误"),
	error_1054(1054,"账号或密码为不能为空"),
	error_1055(1055,"套餐无效"),

	//文件相关
	error_7001(7001,"文件不存在或已被删除"),
	error_7002(7002,"上传的文件类型不支持"),
	error_7003(7003,"无法识别文件类型"),
	error_7004(7004,"空间不足，请扩容或者删除历史文件再上传"),
	error_7005(7005,"上传文件为空文件"),
	error_7006(7006,"文件后缀名与文件类型不匹配"),
	error_7007(7007,"文件受限，禁止此操作"),
	error_7008(7008,"暂时还没有文件轨迹"),
	error_7100(7100,"文件夹不存在或已被删除"),
	error_7101(7101,"该文件夹名称已经存在"),
	error_7102(7102,"父级文件夹不存在"),
	error_7103(7103,"没有可分享的文件"),
	error_7104(7104,"该链接无效，请联系文件所有者重新分享"),
	error_7105(7105,"请先输入正确的分享查阅密码"),
	error_7106(7106,"无效的文件"),
	error_7107(7107,"该文件类型不支持预览"),
	error_7108(7108,"psd转成图片失败"),
	error_7109(7109,"您查看的文件已损坏，请联系服务商重新上传"),
	error_7110(7110,"遍历文件夹出错"),
	error_7111(7111,"文档格式无法识别或文件不存在"),
	error_7112(7112,"查询异常,请稍后重试"),
	error_7113(7113,"文件格式转换异常，请检查源文件，或稍后重试"),
	error_7114(7114,"压缩包中个别文件格式转换失败"),
	error_7115(7115,"未转码的文件，请先转码再查看"),
	error_7116(7116,"删除文件失败"),
	error_7117(7117,"限制上传文件格式为jpg,jepg,png,bmp"),
	error_7118(7118,"文件大小不能超过10MB"),
	error_7120(7120,"身份证反面照不能为空"),
	error_7121(7121,"营业执照不能为空"),
	error_7122(7122,"组织机构代码照不能为空"),
	error_7119(7119,"特征码已存在"),
	error_7123(7123,"身份证正面照不能为空"),
	error_7124(7124,"文件审核中"),
	
	//邮箱、手机验证相关
	error_6001(6001,"发送失败,请检查邮箱账号是否正确"),
	error_6002(6002,"验证码错误"),
	error_6003(6003,"60s内只能发送一次"),
	error_6004(6004,"24小时内只能发送%s次"),
	error_6005(6005,"发送失败，请检查手机号是否正确"),
	error_6006(6006,"短信验证码过期"),
	error_6007(6007,"短信验证码错误"),
	error_6008(6008,"没有可接收邮件的邮箱"),
	error_6009(6009,"邮箱链接过期"),
	error_6010(6010,"邮箱链接错误"),
	error_6011(6011,"手机或邮箱格式错误"),
	error_6012(6012,"手机或邮箱非法，请联系工作人员"),
	
	
	//用户相关
	error_5001(5001,"该邮箱已被使用"),
	error_5002(5002,"密码错误"),
	error_5003(5003,"密码不能为空"),
	error_5004(5004,"该账号不存在"),
	error_5005(5005,"该账号已经被禁用"),
	error_5006(5006,"该账号未激活"),
	error_5007(5007,"该账号已经激活"),
	error_5008(5008,"用户ID不存在"),
	error_5009(5009,"该手机号已被使用"),
	error_5010(5010,"该邮箱已被使用"),
	error_5011(5011,"该手机号码与旧手机号码一致"),
	error_5012(5012,"该邮箱与旧邮箱一致"),
	error_5013(5013,"旧密码错误"),
	error_5014(5014,"用户空间已满"),
	error_5015(5015,"试用用户COOKIE丢失"),
	error_5016(5016,"已验证的邮箱不可更改"),
	error_5017(5017,"新密码不能与旧密码相同"),
	error_5018(5018,"头像压缩处理错误"),
	error_5019(5019,"密码包含非法字符"),
	error_5020(5020,"密码不能为纯数字"),
	error_5021(5021,"密码不能为纯字母"),
	error_5022(5022,"请输入8~16长度字符"),
	error_5023(5023,"不支持该授权平台"),
	error_5024(5024,"该手机号已经被绑定"),
	error_5025(5025,"该先验证手机并绑定本平台账号"),
	error_5026(5026,"快速登录令牌不正确"),
	error_5027(5027,"账号或密码不正确"),
	error_5028(5028,"修改密码失败"),
	error_5029(5029,"用户不存在或身份审核不通过"),
	
	error_200(200,"成功"),
	error_3001(3001,"系统异常"),
	error_3002(3002,"数字签名有误"),
	error_3003(3003,"文件不存在"),
	error_3004(3004,"原图太小，无法嵌入或提取水印"),
	error_3005(3005,"内存不足"),
	error_3006(3006,"参数不正确"),
	error_3007(3007,"打水印失败，该图片颜色信息不适合打水印。请增大图片尺寸，或增加颜色信息"),
	error_3008(3008,"保存结果到目标文件失败"),
	error_3009(3009,"检测不出水印"),
	error_3010(3010,"该格式不支持打水印"),
	error_3011(3011,"不支持该输出文件格式"),
	error_3012(3012,"安全验证失败"),
	error_3013(3013,"sdk购买失败"),
	error_3014(3014,"sdk申请使用失败"),
	error_3015(3015,"该套餐已下线"),
	error_3016(3016,"试用次数已用完，请点击右上角按钮申请正式版本"),

	error_3216(3216,"CA证书申请错误"),
	error_3217(3217,"CA签署时发生错误"),
	error_3218(3218,"CA签署时获取不到接口地址签署时获取不到接口地址"),
	error_3219(3219,"CA签署时其他错误"),
	error_3220(3220,"CA签署生成pdf失败"),
	error_3221(3221,"CA获取时间戳失败"),
	error_3222(3222,"存证失败"),
	error_3223(3223,"签署验证失败"),
	
	error_3301(3301,"以图搜图系统异常"),
	
	error_4001(4001,"存证用户code不能为空"),
	error_4002(4002,"该文件还没有存证"),
	error_4003(4003,"邮寄信息不能为空"),
	;
	
	
	private ErrorCode(int errorCode, String errorMsg) {
		this.errorCode = errorCode;
		this.errorMsg = errorMsg;
	}

	/**
	 * 错误代码
	 */
	private int errorCode;
	/**
	 * 错误描述
	 */
	private String errorMsg;

	public int getErrorCode() {
		return errorCode;
	}

	public String getErrorMsg() {
		return errorMsg;
	}
	
	/**
	 * 根据错误编码获取错误信息
	 * @param errorCode
	 * @return
	 */
	public static String getErrorMsgByCode(int errorCode) {
		ErrorCode[] errors = ErrorCode.values();
		for(ErrorCode error : errors) {
			if(error.getErrorCode() == errorCode) {
				return error.getErrorMsg();
			}
		}
		return "";
	}
	
	/**
	 * 返回数据处理
	 */
	public static Map<String,Object> getCallBack(int code){
		Map<String,Object> resultMap=new HashMap<String,Object>();
		String esg=ErrorCode.getErrorMsgByCode(code);
		resultMap.put("error_code", code);
    	resultMap.put("message", esg);
    	if(code==0){
    		resultMap.put("success", true);
    	}else{
    		resultMap.put("success", false);
    	}
    	resultMap.put("extra_params", null);
		
		return resultMap;
	}
	/**
	 * 返回值处理
	 */
	public static Map<String,Object> getCallBackStr(int code){
		Map<String,Object> resultMap=new HashMap<String,Object>();
		String esg=ErrorCode.getErrorMsgByCode(code);
		resultMap.put("code", code);
    	resultMap.put("message", esg);
		return resultMap;
	}
	
	/**
	 * 返回值处理
	 */
	public static String getCallBackStr(int code, Object data){
		Map<String,Object> resultMap=new HashMap<String,Object>();
		String esg=ErrorCode.getErrorMsgByCode(code);
		resultMap.put("code", code);
    	resultMap.put("message", esg);
    	resultMap.put("data", data);
    	
    	JSONObject jsonObject = JSONObject.fromObject(resultMap);
   
		return jsonObject.toString();
	}
}
